<?php
namespace TennisTournament\Persistent;

interface GenericDao {
    /**
     * Get an entity by its {@link $id}
     * @param $id integer
     * @return an entity if have with such id or null otherwise
     * @throws \Exception
     */
    public function get($id);

    /**
     * Get all entities from specific type
     * @return Array from all entities from specific type
     * @throws \Exception
     */
    public function fetchAll();

    /**
     * Save an specific entity;
     * @param entity
     * @return void
     * @throws \Exception
     */
    public function save($entity);

    /**
     * Delete an specific entity;
     * @param entity
     * @return void
     * @throws \Exception
     */
    public function delete($entity);

    /**
     * Starts a transaction by suspending auto-commit mode.
     * @return void
     */
    public function startTransaction();

    /**
     * Commits a transaction on the underlying database connection.
     */
    public function commitTransaction();

    /**
     * Cancel any database changes done during the current transaction.
     */
    public function rollbackTransaction();
}